package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.DateTimeEnum;
import com.xbongbong.paas.enums.DefaultTypeEnum;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.TuningPoJo;
import com.xbongbong.pro.enums.CommunicatePlanNotifyTypeEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.CustomerCommunicateEnum;
import com.xbongbong.saas.enums.dictionary.CommunicateTypeEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import lombok.Getter;

/**
 * @author long.rao
 * @version v1.0
 * @date 2019/1/17 19:35
 * @since v1.0
 */
@Getter
public enum TempCustomerCommunicateEnum {
    /**
     * 客户跟进记录
     */
    BASE_INFO(CustomerCommunicateEnum.BASE_INFO),
    CUSTOMER_NAME(CustomerCommunicateEnum.CUSTOMER_NAME),
    //CUSTOMER_STATUS(CustomerCommunicateEnum.CUSTOMER_STATUS),
    CONTACT_ARRAY(CustomerCommunicateEnum.CONTACT_ARRAY),
    TYPE(CustomerCommunicateEnum.TYPE),
    COMMUNICATE_TIME(CustomerCommunicateEnum.COMMUNICATE_TIME),
    COMMUNICATE_BUSINESS(CustomerCommunicateEnum.COMMUNICATE_BUSINESS),
    MEMO(CustomerCommunicateEnum.MEMO),
    VIDEO(CustomerCommunicateEnum.VIDEO),
    ADDRESS(CustomerCommunicateEnum.ADDRESS),
    IMAGES(CustomerCommunicateEnum.IMAGES),
    FILE(CustomerCommunicateEnum.FILE),

    ASSOCIATED_INFO(CustomerCommunicateEnum.ASSOCIATED_INFO),
    IF_REMIND(CustomerCommunicateEnum.IF_REMIND),
    NEXT_COMMUNICATE_TIME(CustomerCommunicateEnum.NEXT_COMMUNICATE_TIME),
    NOTIFY_TYPE(CustomerCommunicateEnum.NOTIFY_TYPE),
    NOTIFY_TIME(CustomerCommunicateEnum.NOTIFY_TIME),
    NEXT_NOTIFY_MEMO(CustomerCommunicateEnum.NEXT_NOTIFY_MEMO),
    ENTER_COMMUNICATE_PLAN(CustomerCommunicateEnum.ENTER_COMMUNICATE_PLAN),
    FINISH_COMMUNICATE_PLAN_ID(CustomerCommunicateEnum.FINISH_COMMUNICATE_PLAN_ID),

    SYSTEM_INFO(CustomerCommunicateEnum.SYSTEM_INFO),
    CREATOR_ID(CustomerCommunicateEnum.CREATOR_ID),

    ADD_TIME(CustomerCommunicateEnum.ADD_TIME),
    UPDATE_TIME(CustomerCommunicateEnum.UPDATE_TIME),
    AUTO_GEN(CustomerCommunicateEnum.AUTO_GEN),

    USER_ID(CustomerCommunicateEnum.USER_ID),
    USER_NAME(CustomerCommunicateEnum.USER_NAME),
    USER_AVATAR(CustomerCommunicateEnum.USER_AVATAR),
    CUSTOMER_NAME_LINK_TEXT(CustomerCommunicateEnum.CUSTOMER_NAME_LINK_TEXT),
    CONTACT_NAME_LINK_TEXT(CustomerCommunicateEnum.CONTACT_NAME_LINK_TEXT),
    FINISH_COMMUNICATE_PLAN_LINK_TEXT(CustomerCommunicateEnum.FINISH_COMMUNICATE_PLAN_LINK_TEXT),
    COMMUNICATE_BUSINESS_TYPE(CustomerCommunicateEnum.COMMUNICATE_BUSINESS_TYPE),
    COMMUNICATE_BUSINESS_LINK_TEXT(CustomerCommunicateEnum.COMMUNICATE_BUSINESS_LINK_TEXT),
    AT_USERNAME(CustomerCommunicateEnum.AT_USERNAME),
    ;
    private CustomerCommunicateEnum anEnum;

    TempCustomerCommunicateEnum(CustomerCommunicateEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempCustomerCommunicateEnum> getAllEnum() {
        List<TempCustomerCommunicateEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    /**
     * 初始化跟进方式
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initType(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(CommunicateTypeEnum.class, fieldAttrEntity.getFieldType()));
        fieldAttrEntity.setDictionaryFlag(1);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化拜访时间
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initCommunicateTime(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setDateType(DateTimeEnum.DATETIME.getType());
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.TODAY.getAlias());
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化关联客户
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
        public static void initCustomerName(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.CUSTOMER.getCode());
        fieldAttrEntity.setLinkedText(CUSTOMER_NAME_LINK_TEXT.anEnum.getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        saasParticularAttributePoJo.setRelyMode("customer");
        saasParticularAttributePoJo.setRelyType("base");
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化客户状态
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    /*public static void initCustomerStatus(FieldAttrEntity fieldAttrEntity){
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setRelyMode("customer");
        saasParticularAttributePoJo.setRelyType("relied");
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
    }*/

    /**
     * 初始化关联联系人
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initContactArray(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.CONTACT.getCode());
        fieldAttrEntity.setLinkedText(CONTACT_NAME_LINK_TEXT.anEnum.getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(true);
        saasParticularAttributePoJo.setRelyMode("customer");
        saasParticularAttributePoJo.setRelyType("relied");
        saasParticularAttributePoJo.setRelyBusiness(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
    }

    /**
     * 初始化关联机会
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initOpportunityId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.SALES_OPPORTUNITY.getCode());
//        fieldAttrEntity.setLinkedText(OPPORTUNITY_NAME_LINK_TEXT.anEnum.getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
    }

    /**
     * 初始化关联合同
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initContractId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.CONTRACT.getCode());
//        fieldAttrEntity.setLinkedText(CONTRACT_NAME_LINK_TEXT.anEnum.getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
    }

    /**
     * 初始化同步访客计划
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initFinishCommunicatePlanId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.COMMUNICATE_PLAN.getCode());
        fieldAttrEntity.setLinkedText(FINISH_COMMUNICATE_PLAN_LINK_TEXT.anEnum.getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        saasParticularAttributePoJo.setRelyMode("customer");
        saasParticularAttributePoJo.setRelyType("relied");
        saasParticularAttributePoJo.setRelyBusiness(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
    }

    /**
     * 初始化跟进业务
     *
     * @param fieldAttrEntity 字段属性实体
     * @author long.rao
     * @date 2019-02-12 14:09
     */
    public static void initCommunicateBusiness(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJos = new ArrayList<>();
        ItemPoJo itemPoJo = new ItemPoJo();
        itemPoJo.setText(XbbRefTypeEnum.SALES_OPPORTUNITY.getName());
        Integer opportunityCode = XbbRefTypeEnum.SALES_OPPORTUNITY.getCode();
        itemPoJo.setValue(opportunityCode.toString());
        itemPoJo.setChecked(true);
        itemPoJos.add(itemPoJo);
        ItemPoJo itemPoJo1 = new ItemPoJo();
        itemPoJo1.setText(XbbRefTypeEnum.CONTRACT.getName());
        Integer contractCode = XbbRefTypeEnum.CONTRACT.getCode();
        itemPoJo1.setValue(contractCode.toString());
        itemPoJo1.setChecked(false);
        itemPoJos.add(itemPoJo1);
        ItemPoJo itemPoJo2 = new ItemPoJo();
        itemPoJo2.setText(XbbRefTypeEnum.QUOTATION.getName());
        Integer quotationCode = XbbRefTypeEnum.QUOTATION.getCode();
        itemPoJo2.setValue(quotationCode.toString());
        itemPoJo2.setChecked(false);
        itemPoJos.add(itemPoJo2);
        fieldAttrEntity.setItems(itemPoJos);
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setRelyMode("customer");
        saasParticularAttributePoJo.setRelyType("relied");
        saasParticularAttributePoJo.setRelyBusiness(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
    }

    /**
     * 初始化提醒
     *
     * @param fieldAttrEntity 实体
     */
    public static void initNotifyType(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJos = new ArrayList<>();
        ItemPoJo itemPoJo2 = new ItemPoJo();
        itemPoJo2.setText(CommunicatePlanNotifyTypeEnum.ADVANCE_ONE_QUARTER_HOUR.getAlias());
        itemPoJo2.setValue(CommunicatePlanNotifyTypeEnum.ADVANCE_ONE_QUARTER_HOUR.getCode().toString());
        itemPoJo2.setChecked(true);
        itemPoJos.add(itemPoJo2);
        ItemPoJo itemPoJo3 = new ItemPoJo();
        itemPoJo3.setText(CommunicatePlanNotifyTypeEnum.ADVANCE_ONE_HOUR.getAlias());
        itemPoJo3.setValue(CommunicatePlanNotifyTypeEnum.ADVANCE_ONE_HOUR.getCode().toString());
        itemPoJo3.setChecked(false);
        itemPoJos.add(itemPoJo3);
        ItemPoJo itemPoJo4 = new ItemPoJo();
        itemPoJo4.setText(CommunicatePlanNotifyTypeEnum.ADVANCE_ONE_DAY.getAlias());
        itemPoJo4.setValue(CommunicatePlanNotifyTypeEnum.ADVANCE_ONE_DAY.getCode().toString());
        itemPoJo4.setChecked(false);
        itemPoJos.add(itemPoJo4);
        ItemPoJo itemPoJo5 = new ItemPoJo();
        itemPoJo5.setText(CommunicatePlanNotifyTypeEnum.ADVANCE_THREE_DAY.getAlias());
        itemPoJo5.setValue(CommunicatePlanNotifyTypeEnum.ADVANCE_THREE_DAY.getCode().toString());
        itemPoJo5.setChecked(false);
        itemPoJos.add(itemPoJo5);
        ItemPoJo itemPoJo6 = new ItemPoJo();
        itemPoJo6.setText(CommunicatePlanNotifyTypeEnum.ADVANCE_ONE_WEEK.getAlias());
        itemPoJo6.setValue(CommunicatePlanNotifyTypeEnum.ADVANCE_ONE_WEEK.getCode().toString());
        itemPoJo6.setChecked(false);
        itemPoJos.add(itemPoJo6);
        ItemPoJo itemPoJo7 = new ItemPoJo();
        itemPoJo7.setText(CommunicatePlanNotifyTypeEnum.CUSTOM_TIME.getAlias());
        itemPoJo7.setValue(CommunicatePlanNotifyTypeEnum.CUSTOM_TIME.getCode().toString());
        itemPoJo7.setChecked(false);

        List<String> fieldMap = new ArrayList<>();
        fieldMap.add(NOTIFY_TIME.anEnum.getAttr());
        itemPoJo7.setFieldMap(fieldMap);
        itemPoJos.add(itemPoJo7);
        fieldAttrEntity.setItems(itemPoJos);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(StringConstant.CUSTOM);
        defaultAttrPoJo.setDefaultValue("");
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
    }

    /**
     * 初始化下次拜访时间
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initNextCommunicateTime(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setDateType("yyyy-MM-dd HH:mm");
    }

    /**
     * 初始化下次提醒时间
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initNotifyTime(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setDateType("yyyy-MM-dd HH:mm");
    }

    /**
     * 初始化下次提醒
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initIfRemind(FieldAttrEntity fieldAttrEntity){
        List<String> switchMap = new ArrayList<>();
        switchMap.add(NEXT_COMMUNICATE_TIME.anEnum.getAttr());
        switchMap.add(NOTIFY_TYPE.anEnum.getAttr());
        switchMap.add(NEXT_NOTIFY_MEMO.anEnum.getAttr());
        switchMap.add(ENTER_COMMUNICATE_PLAN.anEnum.getAttr());
        fieldAttrEntity.setSwitchMap(switchMap);
    }

    /**
     * 初始化位置字段
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initAddress(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLocationCenterFlag(0);
        fieldAttrEntity.setLocationCenter(new ArrayList<>());
        TuningPoJo tuningPoJo = new TuningPoJo();
        tuningPoJo.setEnable(1);
        tuningPoJo.setRadius(1000);
        fieldAttrEntity.setTuning(tuningPoJo);
    }
    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initMemo(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditForbidden(0);
        fieldAttrEntity.setAdvancedSetHide(BasicConstant.ZERO);
        fieldAttrEntity.setLinkedText(AT_USERNAME.anEnum.getAttr());
        fieldAttrEntity.setDefaultName(CustomerCommunicateEnum.MEMO.getAttrName());
    }
}
